package com.java.comprehensive.arithmetic.leecode.easy;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: comprehensive-service
 *
 * @description: 搜索插入位置
 *
 * @author: 窦绍飞
 *
 * @create: 2021-11-18 15:56
 **/
public class LeetCode_35 {

	public static int searchInsert(int[] nums, int target) {
		if (nums.length == 0)
			return nums.length;

		int left = 0;
		int right = nums.length-1;
		while (left <= right) {
			int mid = left + (right - left) / 2;

			if (nums[mid] == target) {
				return mid;
			} else if (nums[mid] < target) {
				left = mid + 1;
			} else {
				right = mid - 1;
			}

		}

		return left;
	}

	public static void main(String[] args) throws ParseException {
		int[] nums = { 1, 3 };
		int target = 2;
		int i = searchInsert(nums, target);
		System.out.println(i);
	}
}
